<template>
	<custom-page title="我的广场" backgroundColor="#F9F9F9">
		<template #page>
			<view class="page-content">
				<view class="top-layout">
					<top-tab-bar-news class="tab-view" minWidth="18%" :tabs="tabDatas" :current="current" @changed="onTabItemChange($event)"></top-tab-bar-news>
					<view class="release-view" @click="releaseClick">
						<view></view>
						<view class="release-btn">+</view>
					</view>
				</view>
				<common-list-view ref="mineSquareList" class="list-view" :enableLoadMore="true" :enableRefresh="true"
					@listinit="onListInit($event)" :hasNoDataHolder="true">
					<template #content='{datas}'>
						<view class="assistant-video-view">
							<assistant-video-item v-for="(item, index) in datas" :itemData="item" @itemClick="videoClick(item)"></assistant-video-item>
						</view>
						<view style="height: 32rpx;"></view>
					</template>
				</common-list-view>
			</view>
		</template>
	</custom-page>
</template>
<script>
	import {
		storageUserType
	} from '../../global/config.js'
	export default {
		data() {
			return {
				tabDatas: [
					{
						text: '全部'
					},
					{
						text: '审核中',
						value: 0
					},
					{
						text: '审核通过',
						value: 1
					},
					{
						text: '审核不通过',
						value: 2
					}
				],
				current: 0,
				userId: '',
				userType: '1',	     //用户类型 1 - 普通用户 2 - 助教用户
			}
		},
		onLoad(val) {
			this.userType = uni.getStorageSync(storageUserType)
			this.userId = val.userId
		},
		methods: {
			onListInit(event){
				event.target.loadPageData = ({start, pageSize, showLoading = false}) => {
					let params = {
						current: start,
						pageSize: pageSize,
						status: this.tabDatas[this.current].value,		//0-待审核1-审核通过2-审核不通过
						userId: this.userId,
						showType: (this.userType=='2')?'0':'4',		//类别0-广场助教风采视频1-广场助教图片2-个人中心视频3-个人中心图片4-广场球友发风采视频5-广场球友风采图片	
						sourceType: '1',		//0-管理后台列表 1-app或小程序广场 2-app小程序个人中心	
					}
					return this.requestCenter.getSquareAssistantVideo(params)
					.then(res => {
						return Promise.resolve({ 
							curPage: start,
							pageCount: res.pages || 1,
							datas: res.records || []
						})
					})
				}
			},
			
			//tab切换
			onTabItemChange: function(event) {
				this.current = event.value
				this.refreshList()
			},
			
			//数据刷新
			refreshList(){
				this.$refs.mineSquareList.triggerLoadData({start: 1, showLoading: true})
			},
			
			//点击发布
			releaseClick(){
				uni.navigateTo({
					url: '/pages/square-release/square-release',
					events: {
						videoRelease: (data)=> {
							this.refreshList()
						}
					}
				})
			},
			
			//视频点击
			videoClick(item){
				uni.navigateTo({
					url: '/pages/square-video-detail/square-video-detail?isOperation=1',
					success: function(res) {
					    res.eventChannel.emit('squareVideoInfo', { data: item})
					},
					events: {
						videoRelease: (data)=> {
							this.refreshList()
						}
					}
				})
			}
		}
	}
</script>

<style scoped lang="less">
	.page-content{
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
	}
	.top-layout{
		display: flex;
		flex-direction: row;
		align-items: center;
		background-color: white;
		.tab-view{
			flex: 1;
		}
		.release-view{
			display: flex;
			flex-direction: row;
			align-items: center;
			font-size: 28rpx;
			color: #021624;
			.release-btn{
				width: 64rpx;
				height: 48rpx;
				line-height: 38rpx;
				background: #021624;
				color: white;
				font-size: 36rpx;
				font-weight: bold;
				text-align: center;
				border-radius: 14rpx;
				margin-left: 16rpx;
				margin-right: 32rpx;
			}
		}
	}
	.list-view{
		flex: 1;
		overflow: hidden;
	}
	.assistant-video-view{
		width: 100%;
		display: flex;
		padding: 0 16rpx;
		box-sizing: border-box;
		flex-direction: row;
		justify-content: space-between;
		flex-wrap: wrap;
	}
</style>
